package com.example.qrarexplorer;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.Menu;

import com.dlazaro66.qrcodereaderview.QRCodeReaderView;
import com.dlazaro66.qrcodereaderview.QRCodeReaderView.OnQRCodeReadListener;
import com.example.processing3d.TransparentSurfaceFragment;
import com.monyetmabuk.rajawali.tutorials.R;
import com.monyetmabuk.rajawali.tutorials.examples.AExampleFragment;

public class QRar extends Activity implements OnQRCodeReadListener{

	private QRCodeReaderView mydecoderview;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_qrar);
        mydecoderview = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
        mydecoderview.setOnQRCodeReadListener(this);
        
		final android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
		try {
			Fragment fragment = (Fragment) TransparentSurfaceFragment.instantiate(this, "");

			final Bundle bundle = new Bundle();
			bundle.putString(AExampleFragment.BUNDLE_EXAMPLE_URL, exampleItem.getUrl(category));
			fragment.setArguments(bundle);

			if (fragmentManager.findFragmentByTag(FRAGMENT_TAG) != null)
				transaction.addToBackStack(null);
			
			transaction.replace(R.id.content_frame, fragment, FRAGMENT_TAG);
			transaction.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.qrar, menu);
		return true;
	}
	
	@Override
	public void onQRCodeRead(String text, PointF[] points) {
		if (text.contains("www.youtube.com") == true)
		{
		}		    
	}
	
	@Override
	public void cameraNotFound() {
		
	}

	// Called when there's no QR codes in the camera preview image
	@Override
	public void QRCodeNotFoundOnCamImage() {
		
	}
    
	@Override
	protected void onResume() {
		super.onResume();

		mydecoderview.getCameraManager().startPreview();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		mydecoderview.getCameraManager().stopPreview();
	}

}
